package wsz.service.impl;

import org.apache.dubbo.config.annotation.Service;
import wsz.AsyncService;

import java.util.concurrent.CompletableFuture;

/**
 * TODO：
 *
 * @author wsz
 * @desc：
 * @date 2021/12/13
 */
@Service
public class AsyncServiceImpl implements AsyncService {
    @Override
    public CompletableFuture<String> sayHello(String msg, int wait) {
        System.out.println("AsyncServiceImpl-" + msg + "--" + wait);
        // 建议为supplyAsync提供自定义线程池，避免使用JDK公用线程池
        return CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(wait);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "async response from provider.==" + msg;
        });
    }
}
